

package com.hazelcast.client.splitbrainprotection;

import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.client.config.RoutingMode;
import com.hazelcast.client.test.TestHazelcastFactory;
import com.hazelcast.cluster.Address;
import com.hazelcast.core.HazelcastInstance;

import static com.hazelcast.test.Accessors.getNode;

@SuppressWarnings("WeakerAccess")
public class SplitBrainProtectionTestUtil {

    private SplitBrainProtectionTestUtil() {
    }

    public static HazelcastInstance createClient(TestHazelcastFactory factory, HazelcastInstance instance) {
        return factory.newHazelcastClient(getClientConfig(instance));
    }

    public static ClientConfig getClientConfig(HazelcastInstance instance) {
        ClientConfig clientConfig = new ClientConfig();
        Address address = getNode(instance).address;
        clientConfig.getNetworkConfig().addAddress(address.getHost() + ":" + address.getPort());
        clientConfig.getNetworkConfig().getClusterRoutingConfig().setRoutingMode(RoutingMode.SINGLE_MEMBER);
        clientConfig.setClusterName(instance.getConfig().getClusterName());
        return clientConfig;
    }
}
